﻿@model GitCandy.Models.TreeModel

@{
    ViewBag.Title = string.Format(SR.Shared_TitleFormat, string.Format(SR.Repository_TreeTitle, Model.RepositoryName, Model.ReferenceName ?? Model.Commit.Sha.ToShortSha(), Model.Path));
}

<h3>@Html.ActionLink(Model.RepositoryName, "Tree", Html.OverRoute(new { path = "" }))</h3>

@if (Model.Entries == null)
{
    <div>
        @Html.ActionLink(SR.Shared_Detail, "Detail", Html.OverRoute(), new { @class = "btn btn-default pull-right" })
        @Html.Partial("_GitUrlButton", Model.GitUrls)
    </div>
    <div class="alert alert-info">@SR.Repository_EmptyWords</div>
}
else
{
    <div>
        @if (Model.IsRoot)
        {
            <h5>@Model.Description</h5>
            <div class="border-area">
                <ul class="nav nav-justified">
                    <li>@Html.ActionLink(Model.Scope.Commits + " " + SR.Repository_Commits, "Commits", Html.OverRoute())</li>
                    <li>@Html.ActionLink(Model.Scope.Branches + " " + SR.Repository_Branches, "Branches", Html.OverRoute(new { path = "" }))</li>
                    <li>@Html.ActionLink(Model.Scope.Tags + " " + SR.Repository_Tags, "Tags", Html.OverRoute(new { path = "" }))</li>
                    <li>@Html.ActionLink(Model.Scope.Contributors + " " + SR.Repository_Contributors, "Contributors", Html.OverRoute())</li>
                </ul>
            </div>
        }

        <div>
            @if (Model.IsRoot)
            {
                @Html.ActionLink(SR.Shared_Detail, "Detail", Html.OverRoute(), new { @class = "btn btn-default pull-right" })
                @Html.Partial("_BranchSelector", Model.BranchSelector)
                @Html.Partial("_ZipButton", Model.ReferenceName ?? Model.Commit.Sha)
                <a href="@Url.Action("Compare", Html.OverRoute(new { path = "" }))" class="btn btn-default"><span class="glyphicon glyphicon-retweet"></span>@SR.Repository_Compare</a>
                @Html.Partial("_GitUrlButton", Model.GitUrls)
            }
            else
            {
                @Html.Partial("_BranchSelector", Model.BranchSelector)
                <div class="btn-group">
                    @Html.ActionLink(SR.Repository_History, "Commits", Html.OverRoute(new { path = (Model.ReferenceName ?? Model.Commit.Sha) + "/" + Model.Path }), new { @class = "btn btn-default" })
                </div>
            }
        </div>
        @Html.Partial("_PathBar", Model.PathBar)
        <div class="border-area table-responsive">
            <table class="table table-hover table-striped">
                <caption>
                    <div class="clearfix">
                        <div title="@Model.Commit.CommitMessageShort" class="pull-left">@Html.ActionLink(Model.Commit.CommitMessageShort.ShortString(80), "Commit", Html.OverRoute(new { path = Model.Commit.Sha }))</div>
                    </div>
                    <div class="clearfix">
                        <strong title="@Model.Commit.Author">@Model.Commit.Author.Name</strong>
                        <span>@SR.Repository_AuthoredAt</span>
                        <span title="@Model.Commit.Author.When">@Model.Commit.Author.When.LocalDateTime</span>
                        @if (Model.Commit.Author != Model.Commit.Committer)
                        {
                            <strong title="@Model.Commit.Committer">@Model.Commit.Committer.Name</strong>
                            <span>@SR.Repository_CommittedAt</span>
                            <span title="@Model.Commit.Committer.When">@Model.Commit.Committer.When.LocalDateTime</span>
                        }
                        <div class="pull-right">@Model.Commit.Sha.ToShortSha()</div>
                    </div>
                </caption>
                <tbody>
                    @foreach (var entry in Model.Entries)
                    {
                        <tr>
                            <td>
                                <span title="@entry.Name">
                                    @if (entry.EntryType == LibGit2Sharp.TreeEntryTargetType.Tree)
                                    { <span class="glyphicon glyphicon-folder-close"></span> }
                                    else if (entry.EntryType == LibGit2Sharp.TreeEntryTargetType.Blob)
                                    { <span class="glyphicon glyphicon-file"></span> }
                                    else if (entry.EntryType == LibGit2Sharp.TreeEntryTargetType.GitLink)
                                    { <i class="glyphicon glyphicon-bookmark"></i> }
                                    else
                                    { <span class="glyphicon glyphicon-leaf"></span> }
                                    @if (entry.EntryType == LibGit2Sharp.TreeEntryTargetType.GitLink)
                                    { @entry.Name.ShortString(25) }
                                    else
                                    { @Html.ActionLink(entry.Name.ShortString(25), entry.EntryType.ToString(), Html.OverRoute(new { path = (Model.ReferenceName ?? Model.Commit.Sha) + "/" + entry.Path })) }
                                </span>
                            </td>
                            <td><span title="@entry.Commit.CommitMessageShort">@(entry.Commit.Sha == null ? Html.Raw(entry.Commit.CommitMessageShort) : Html.ActionLink(entry.Commit.CommitMessageShort.ShortString(70), "Commit", Html.OverRoute(new { path = entry.Commit.Sha })))</span></td>
                            <td title="@entry.Commit.Author">@entry.Commit.Author.Name.ShortString(20)</td>
                            <td title="@entry.Commit.Author.When">@entry.Commit.Author.When.LocalDateTime.ToShortDateString()</td>
                        </tr>
                    }
                </tbody>
            </table>
        </div>
        @if (Model.Readme != null)
        {
            <div class="border-area">
                <table class="table">
                    <caption>
                        <div class="pull-left keep-space"><i class="glyphicon glyphicon-list-alt"></i> @Model.Readme.Name</div>
                    </caption>
                    <tbody>
                        <tr>
                            <td>
                                @Html.Partial("_BlobPreview", Model.Readme)
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        }
    </div>
}